<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/28 0028
 * Time: 20:22
 */

namespace app\storage\model;

use think\Model;

class FeedModel extends Model
{
    protected $table = 'smt_feed_station';
    protected $pk = 'uuid';

    /***
     * @return \think\model\relation\BelongsTo
     * 建立与仓库的连接
     */
    public function Storage()
    {
        return $this->belongsTo('StorageModel', 'storage_uuid', 'uuid')->bind('name');
    }
    /***
     * 添加料站表
     */
    public function add($data){

    }


    /****
     * @param $condition
     * @return mixed
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取料站表
     */
    public function getFeed($condition){
        $where = $condition['where'];
        $pageIndex = $condition['pageIndex'];
        $pageSize = $condition['pageSize'];
        $ret['total'] = $this->where($where)->count();
        $ret['row'] = $this->with('Storage')
            ->where($where)->order('time desc')
            ->page($pageIndex,$pageSize)
            ->select();
        return $ret;
    }

    /***
     * @param $where
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\Exception
     * 根据条件返回一条料站表记录
     */
    public function findFeed($where){
        $result = $this->where($where)->find();
        return $result;
    }


}